#include "NxDataConfiguration.h"

NJGIS::SERVICE::NjDataConfiguration::~NjDataConfiguration()
{

}

int NJGIS::SERVICE::NjDataConfiguration::getCount()
{
	return this->_items.size();
}

int NJGIS::SERVICE::NjDataConfiguration::insertData( const char* state, const char* event, const char* dataid, bool destoryed, bool requested, bool optional)
{
	for(int i = 0; i < this->_items.size(); i++)
	{
		if((strcmp(this->_items[i].state, state) == 0) && (strcmp(this->_items[i].event, event) == 0))
		{
			char* cdataid = new char[strlen(dataid)];
			this->_items[i].data = cdataid;
			this->_items[i].destoryed = destoryed;
			return 2;
		}
	}
	NjDataConfigItem item;
	char* cstate = new char[strlen(state)];
	char* cevent = new char[strlen(event)];
	char* cdataid = new char[strlen(dataid)];
	strcpy(cstate, state);
	strcpy(cevent, event);
	strcpy(cdataid,dataid);
	item.state = cstate;
	item.event = cevent;
	item.data = cdataid;
	item.destoryed = destoryed;
	this->_items.push_back(item);
	return 1;
}

int NJGIS::SERVICE::NjDataConfiguration::getData( int index, std::string &state, std::string &event, std::string &dataid, bool &destoryed )
{
	if(index > (this->_items.size() - 1) || index < 0)
	{
		return -2;
	}
	for(int i = 0; i < this->_items.size(); i++)
	{
		if(i == index)
		{
			state = std::string(this->_items[i].state);
			event = std::string(this->_items[i].event);
			dataid = this->_items[i].data;
			destoryed = this->_items[i].destoryed;
			return 1;
		}
	}
	return 0;
}

const char* NJGIS::SERVICE::NjDataConfiguration::getDataID( const char* state, const char* event )
{
	for(int i = 0; i < this->_items.size(); i++)
	{
		if((strcmp(this->_items[i].state, state) == 0) && (strcmp(this->_items[i].event, event) == 0))
		{
			return this->_items[i].data;
		}
	}
	return NULL;
}
